package com.xbq.exceleditor.bean.viewmodel

import androidx.lifecycle.ViewModel
import com.xbq.exceleditor.db.ExcelDatabase
import com.xbq.exceleditor.db.entity.ExcelBean
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
 * Author: liaohaiping
 * Time: 2020-10-30
 * Description:
 */
@HiltViewModel
class MyDocumentViewModel @Inject constructor(val db: ExcelDatabase) : ViewModel() {
    private val PAGE_SIZE = 20
    private var pageIndex: Int = 0
    private var offset: Int = 0

    suspend fun findFirstPage(): List<ExcelBean> {
        pageIndex = 0
        offset = PAGE_SIZE * pageIndex
        val docs = db.docDao().findAll(PAGE_SIZE, offset)
        return docs
    }

    suspend fun findNextPage(): List<ExcelBean> {
        pageIndex += 1
        offset = pageIndex * PAGE_SIZE
        return db.docDao().findAll(PAGE_SIZE, offset)
    }
}